package com.ourway.constant;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 * 飞书常量配置类
 *
 * @author lwh
 * @date 2021/11/23
 */
@Data
@Configuration
@PropertySource("classpath:feishu.properties")
public class FeiShuConstants {

    @Value("${feishu.appId}")
    private String appId;

    @Value("${feishu.appSecret}")
    private String appSecret;

    @Value("${feishu.requestUrl.tenantAccessToken}")
    private String tenantAccessTokenRedirectUrl;

    @Value("${feishu.requestUrl.loginRedirect}")
    private String loginRedirectUrl;

    @Value("${feishu.requestUrl.loginCallBack}")
    private String loginCallBackUrl;

    @Value("${feishu.requestUrl.userAccessToken}")
    private String userAccessTokenUrl;

    @Value("${feishu.requestUrl.subScribeApproval}")
    private String subScribeApprovalUrl;

    @Value("${feishu.requestUrl.approvalInstanceInfo}")
    private String approvalInstanceInfoUrl;

    @Value("${feishu.requestUrl.approveInstance}")
    private String approveInstanceUrl;

    private String userInfoUrl;

    private String sendMessageUrl;

    private String replyMessageUrl;

    private String searchChildDepartmentUrl;

    private String searchUserByParentDepartmentUrl;

    @Value("${feishu.requestUrl.createDepartment}")
    private String createDepartmentUrl;

    @Value("${feishu.approvalCode.leave}")
    private String leaveApprovalCode;

    private String updateLeaveMessageCardUrl;

    private String updateUserUrl;

    private String departmentInfoUrl;

    @Value("${feishu.requestUrl.createUser}")
    public String createUserUrl;

    private String deleteUserUrl;

    private String updateDeptUrl;

    private String deleteDeptUrl;

    public static final String EVENT_SUBSCRIBE_TYPE_ROBOT_RECEIVE_MESSAGE = "im.message.receive_v1";

    public String getReplyMessageUrl(String messageId) {
        return "https://open.feishu.cn/open-apis/im/v1/messages/" + messageId +"/reply";
    }

    public String getUserInfoUrl(String userId) {
        return "https://open.feishu.cn/open-apis/contact/v3/users/" + userId;
    }

    /**
     * @param receiveIdType open_id/user_id/union_id/email/chat_id
     */
    public String getSendMessageUrl(String receiveIdType) {
        return "https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=" + receiveIdType;
    }

    /**
     * @param departmentId 部门ID，根部门为0
     */
    public String getSearchChildDepartmentUrl(String departmentId) {
        return "https://open.feishu.cn/open-apis/contact/v3/departments/"+ departmentId +"/children";
    }

    public String getSearchUserByParentDepartmentUrl(String departmentId) {
        return "https://open.feishu.cn/open-apis/contact/v3/users/find_by_department?department_id=" + departmentId;
    }

    public String getUpdateLeaveMessageCardUrl(String messageId) {
        return "https://open.feishu.cn/open-apis/im/v1/messages/" + messageId;
    }

    public String getUpdateUserUrl(String openId) {
        return "https://open.feishu.cn/open-apis/contact/v3/users/" + openId;
    }

    public String getDepartmentInfoUrl(String deptId) {
        return "https://open.feishu.cn/open-apis/contact/v3/departments/" + deptId;
    }

    public String getDeleteUserUrl(String userId) {
        return "https://open.feishu.cn/open-apis/contact/v3/users/" + userId;
    }

    public String getUpdateDeptUrl(String deptId) {
        return "https://open.feishu.cn/open-apis/contact/v3/departments/" + deptId;
    }

    public String getDeleteDeptUrl(String deptId) {
        return "https://open.feishu.cn/open-apis/contact/v3/departments/" + deptId;
    }
}
